# NOT RUN {
##
## Range notation
##
ipv4r("192.0.0.0-192.0.0.10")
##
## CIDR notation
##
## The entire IPv4 address space
ipv4(ipv4r('0.0.0.0/0'))
## Is there life on Mars ? (Martian packets)
ipv4r("100.64.0.0/10")
##
ip4 <- ipv4("192.0.0.0")
## power of 2
ipv4r( print(sprintf("%s-%s", ip4, ip4 + ( 2^8-1) ) ))
## not a power of 2
ipv4r( print(sprintf("%s-%s", ip4, ip4 + 10 ) ))
##
## Network classes
##
ip.class <- data.frame(
name = paste('class', LETTERS[1:5])
, class = ipv4r(
c(
'0.0.0.0/8' ## Class A
, '128.0.0.0/16' ## Class B
, '192.0.0.0/24' ## Class C
, '224.0.0.0-239.255.255.255' ## Class D
, '240.0.0.0-255.255.255.255' ## Class E
)
)
)
##
## extract IP range start and end
##
(class.ip <- ipv4(ip.class$class))
##
lo(ip.class$class)==class.ip$lo
##
hi(ip.class$class)==class.ip$hi
##
## # of hosts on this network
##
ip.range(ip.class$class)
## this is ok for IP v4 but may cause loss of precision for IPv6
ip.range(ip.class$class)==as.numeric(class.ip$hi - class.ip$lo)
##
##
##
ipr0 <- ipr()
##
ipr0[3] <- ipv4r(
"0.0.0.0", "0.0.0.1"
)
ipr0[5] <- ipv6r(
"::" , 0L
)
ipr0
##
ipr0 <- ipr()
ipr0[2] <- NA
ipr0
# }
Run the code above in your browser using DataLab